package testcasetool.transformation.presentation;

import org.apache.commons.lang3.StringUtils;

import testcasetool.transformation.uml.utp.Action_TestComponent;
import testcasetool.transformation.uml.utp.Parameter_DataPool;
import testcasetool.transformation.uml.utp.TestCase_TestCase;

public class TestCaseViewer {

	public static void printTestCase(TestCase_TestCase tc) {
		imprimirLineaBorde();
		imprimirLineaInterior();
		insertarRow2Columnas("Nombre", tc.getName());
		imprimirLineaInterior();
		insertarRow2Columnas("Escenarios Cubiertos" , StringUtils.join(tc.getTestScenario().getTestTrail(), " -> "));
		imprimirLineaInterior();
		String precondiciones = tc.getPreconditions();
		insertarRow2Columnas("Precondiciones" , ((precondiciones != null) ?precondiciones : "Ninguna"));
		imprimirLineaInterior();
		System.out.format("| %-192s |\n", "PASOS");
		imprimirLineaInterior();
		System.out.format("| ID | %-25s | %-110s | %-50s |\n", "Paso" , "Descripcion", "Parametros");
		imprimirLineaInterior();

		for (Action_TestComponent action : tc.getTestScenario().getTestSteps()) {
			imprimirRowPaso(action);
		}
		
		imprimirLineaInterior();
		insertarRow2Columnas("Resultado Esperado" , tc.getTestScenario().getPostCondition());

		imprimirLineaBorde();	
		System.out.println();
	}

	private static void imprimirRowPaso(Action_TestComponent action) {
		Parameter_DataPool param = action.getActionParameter();
		// TODO Valores de prueba
		System.out.format("| %-2s | %-25s | %-110s | %-50s |\n", 
				action.getActionId() , action.getActionName() , action.getActionDescription() , 
				(param != null)? param.toString() : "");
	}

	private static void insertarRow2Columnas(String columnName, String value) {
		System.out.format("| %-30s | %-164s |\n", columnName , value);
	}

	private static void imprimirLineaBorde() {
		System.out.println("+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+");
	}
	private static void imprimirLineaInterior() {
		System.out.println("|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|");
	}
}
